﻿package plugin.instances.game
{
    import com.core.*;
    import com.sh.game.util.*;
    import flash.events.*;
    import flash.utils.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.instances.*;
    import uiresource.instances.ui.*;
    import view.mornExtends.*;
    import view.uilt.*;

    public class SwyGame extends SwyUI implements IInstance
    {
        private var maxFloor:int = 0;
        private var curFloor:int = 0;

        public function SwyGame()
        {
            return;
        }// end function

        public function initShow(param1:Object, param2:Dictionary) : void
        {
            var _loc_3:Object = null;
            for (_loc_3 in param2)
            {
                
                this.updateShow(int(_loc_3), param2[_loc_3]);
            }
            this.showItem(param1.show);
            txt_num.addEventListener(TextEvent.LINK, this.doLink);
            shuoming.toolTip = param1.tips.replace(/#""#/g, "\n");
            return;
        }// end function

        private function showItem(param1:String) : void
        {
            var _loc_2:* = new ItemSplit();
            var _loc_3:* = _loc_2.doSplits(param1, "&", "/", "#");
            list_goods.array = _loc_3[0];
            list_goods.renderHandler = new Handler(this.itemRender);
            return;
        }// end function

        private function itemRender(param1:Component, param2:int) : void
        {
            if (param2 < list_goods.length)
            {
                (param1 as FlashItem).data = list_goods.array[param2];
            }
            return;
        }// end function

        public function updateShow(param1:int, param2:Object) : void
        {
            var _loc_3:Object = null;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_6:Object = null;
            var _loc_7:Object = null;
            var _loc_8:Object = null;
            var _loc_9:ItemSplit = null;
            var _loc_10:Array = null;
            var _loc_11:Object = null;
            switch(param1)
            {
                case InstancesPublic.TIMECHECKER:
                {
                    txt_time.text = TimeDataFormatUtil.getLeftTime(int(param2));
                    break;
                }
                case InstancesPublic.SWYMSG:
                {
                    txt_maxnum.text = param2.maxfloor;
                    this.maxFloor = param2.maxfloor;
                    this.curFloor = param2.floor;
                    ModelProxy.change("data", "shenweiyuFloor", {current:param2.floor, max:param2.maxfloor});
                    txt_state.isHtml = true;
                    txt_state.text = !param2.bosshere ? ("<font color=\'#53b436\'>已击杀</font>") : ("<font color=\'#c72514\'>未击杀</font>");
                    _loc_3 = ConfigDictionary.data.shenweiyu;
                    _loc_7 = _loc_3[param2.floor];
                    _loc_4 = ItemUilt.getAllCount(_loc_7.need);
                    _loc_5 = param2.maxfloor == param2.floor ? (_loc_7.num) : (0);
                    if (_loc_5 > _loc_4)
                    {
                        txt_num.text = "<font color=\'#c72514\'>" + _loc_4 + "/" + _loc_5 + "</font>";
                    }
                    else
                    {
                        _loc_6 = ConfigDictionary.data.sysnpc[_loc_7.npcid];
                        txt_num.text = "<font color=\'#53b436\'>" + _loc_4 + "/" + _loc_5 + "</font>    <font color=\'#52B730\'><u><a href=\'event:1&" + _loc_6.stageid + "#" + _loc_6.x + "#" + _loc_6.y + "#" + _loc_6.npcid + "\'>点击前往下一层</a></u></font>";
                    }
                    _loc_8 = _loc_3[param2.maxfloor];
                    _loc_9 = new ItemSplit();
                    _loc_10 = _loc_9.doSplits(_loc_8.sum, "&", "/", "#");
                    if (_loc_10[0][0])
                    {
                        txt_dianquan.text = _loc_10[0][0].count;
                    }
                    else
                    {
                        txt_dianquan.text = "0";
                    }
                    if (_loc_10[1][0])
                    {
                        txt_heitie.text = _loc_10[1][0].count;
                    }
                    else
                    {
                        txt_heitie.text = "0";
                    }
                    break;
                }
                case InstancesPublic.SWYBOSSKILL:
                {
                    ModelProxy.change("data", "swyBossState", false);
                    txt_state.text = "<font color=\'#53b436\'>已击杀</font>";
                    break;
                }
                case InstancesPublic.UPDATEBAG:
                {
                    _loc_3 = ConfigDictionary.data.shenweiyu;
                    _loc_11 = _loc_3[this.curFloor];
                    _loc_4 = ItemUilt.getAllCount(_loc_11.need);
                    _loc_5 = this.curFloor == this.maxFloor ? (_loc_11.num) : (0);
                    if (_loc_5 > _loc_4)
                    {
                        txt_num.text = "<font color=\'#c72514\'>" + _loc_4 + "/" + _loc_5 + "</font>";
                    }
                    else
                    {
                        _loc_6 = ConfigDictionary.data.sysnpc[_loc_11.npcid];
                        txt_num.text = "<font color=\'#53b436\'>" + _loc_4 + "/" + _loc_5 + "</font>    <font color=\'#52B730\'><u><a href=\'event:1&" + _loc_6.stageid + "#" + _loc_6.x + "#" + _loc_6.y + "#" + _loc_6.npcid + "\'>点击前往下一层</a></u></font>";
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        protected function doLink(event:TextEvent) : void
        {
            var _loc_2:Array = null;
            var _loc_3:Array = null;
            _loc_2 = event.text.split("&");
            switch(int(_loc_2[0]))
            {
                case 1:
                {
                    _loc_3 = _loc_2[1].split("#");
                    ModelProxy.change("data", "taskfindpath", _loc_3[3]);
                    ModelProxy.change("zone", "autoMove", {x:_loc_3[1], y:_loc_3[2], tostageid:_loc_3[0], onhorse:false});
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function destroyShow(param1:Dictionary) : void
        {
            return;
        }// end function

        public function initEvent() : void
        {
            btn_tuichu.clickHandler = new Handler(this.doTuichu);
            return;
        }// end function

        private function doTuichu() : void
        {
            ModelProxy.change("zone", "exitInstance", null);
            return;
        }// end function

        public function removeEvent() : void
        {
            return;
        }// end function

    }
}
